<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Session data</title>
</head>
<body bgColor="white">
<?php


   if (!isset($_GET['sessionName']) && !file_exists($_GET['sessionName'])) {
	 echo "Bad name of session. <BR/> Existing ones are : <BR/>";
	
		// dossier listé (pour lister le répertoir courant : $dir_nom = '.'  --> ('point')
		$dir_nom = '.'; 
		 // on ouvre le contenu du dossier courant
		$dir = opendir("traces_files") or die('Erreur de listage : le répertoire n\'existe pas');
		// on déclare le tableau contenant le nom des fichiers
		$fichier= array(); 
		// on déclare le tableau contenant le nom des dossiers
		$dossier= array(); 

		while($element = readdir($dir)) 
		{
			if($element != '.' && $element != '..') 
			{
				if (!is_dir($dir_nom.'/'.$element)) 
				{
					echo $element . "<BR/>";
				}
				else 
				{
					$dossier[] = $element;
				}
			}
		}

	}
	else {
		$sessionName = "traces_files/" . $_GET['sessionName'];
		$array = file($sessionName);
		echo "<script>";
		echo "messages = [ ";
		foreach ($array as $i => $value) {
		    echo ($value) . ",";
		}
		echo "]\n";
		echo "</script>";
		//echo count($array);
		/*echo "<script>";
		echo "messages = eval (".str_replace(',' , ',\n' , str_replace('"]',"]",str_replace('["',"[",str_replace("\\","",str_replace("\\n","",json_encode($array))))). " );";
		echo "</script>";
    	*/
	}

	
        	
?>
 UserId
 ,Time
 ,AF_EngagementBoredom
 ,AF_Frustration
 ,AF_Meditation
 ,AF_ST_Excitement
 ,AF_LT_Excitement
 ,CO_Action
 ,CO_Power
 ,EX_Lower_Action
 ,EX_Lower_Power
 ,EX_Upper_Action
 ,EX_Upper_Power
 ,Eyes
 ,Eyes_Looking
<BR/>
<script>
for (var i=0;i<messages.length;i++) {
	var msg=messages[i].message;
	if (msg.UserId!=null && msg.Time!=null && msg.EmoState!=null)
	document.write(
		msg.UserId + "," +
		msg.Time + "," +
		msg.EmoState.AF_EngagementBoredom+ "," +
		msg.EmoState.AF_Frustration+ "," +
		msg.EmoState.AF_Meditation+ "," +
		msg.EmoState.AF_ST_Excitement+ "," +
		msg.EmoState.AF_LT_Excitement+ "," +
		msg.EmoState.CO_Action+ "," +
		msg.EmoState.CO_Power+ "," +
		msg.EmoState.EX_Lower_Action+ "," +
		msg.EmoState.EX_Lower_Power+ "," +
		msg.EmoState.EX_Upper_Action+ "," +
		msg.EmoState.EX_Upper_Power+ "," +
		msg.EmoState.Eyes+ "," +
		msg.EmoState.Eyes_Looking+"<BR/>"
	);
}
</script>

<BR/><BR/>
</body>
</html>